<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" /> 
    <title> - 天地维杰网</title>
    <meta name="keywords" content="系统架构,shutdown,不与天斗,Domino,博客,程序员,架构师,笔记,技术,分享,java,Redis">
    
    <meta property="og:title" content="">
    <meta property="og:site_name" content="天地维杰网">
    <meta property="og:image" content="/img/author.jpg"> 
    <meta name="title" content=" - 天地维杰网" />
    <meta name="description" content="天地维杰网 | 博客 | 软件 | 架构 | Java "> 
    <link rel="shortcut icon" href="http://www.shutdown.cn/img/favicon.ico" />
    <link rel="apple-touch-icon" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link rel="apple-touch-icon-precomposed" href="http://www.shutdown.cn/img/apple-touch-icon.png" />
    <link href="http://www.shutdown.cn/js/vendor/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/main.css" rel="stylesheet" type="text/css" />
    <link href="http://www.shutdown.cn/css/syntax.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"left","display":"post"},
     fancybox: true, 
    motion: true
  };
</script>
</head>
<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">
<div class="container one-collumn sidebar-position-left page-home  ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"> <div class="site-meta  custom-logo ">

  <div class="custom-logo-site-title">
    <a href="http://www.shutdown.cn"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">天地维杰网</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">人如秋鸿来有信，事若春梦了无痕</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
    <ul id="menu" class="menu">
      
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />首页
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/redis/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-battery-full"></i> <br />Redis
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/java/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-coffee"></i> <br />java
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/linux/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-linux"></i> <br />linux
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/daily/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bug"></i> <br />日常问题
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-child"></i> <br />Spring和Springboot
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/spring/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-fire"></i> <br />Mac相关
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-gavel"></i> <br />中间件
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/front/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-bolt"></i> <br />前端
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/categories/jvm/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-balance-scale"></i> <br />JVM
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/post/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />归档
          </a>
        </li>
      
        <li class="menu-item ">
          <a href="http://www.shutdown.cn/about/" rel="section">
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />关于
          </a>
        </li>
      
      <li class="menu-item menu-item-search">
        <a href="javascript:;" class="popup-trigger"> <i class="menu-item-icon fa fa-search fa-fw"></i> <br /> 搜索</a>
      </li>
    </ul>
    <div class="site-search">
      <div class="popup">
 <span class="search-icon fa fa-search"></span>
 <input type="text" id="local-search-input">
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>

    </div>
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            
<section id="posts" class="posts-expand">
  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <header class="post-header">
      <h1 class="post-title" itemprop="name headline">
        <a class="post-title-link" href="http://www.shutdown.cn/post/%E5%AE%9E%E4%BE%8B%E9%9B%86%E7%BE%A4%E7%8A%B6%E6%80%81%E4%B8%BAfail%E5%AF%BC%E8%87%B4%E7%9A%84%E9%9B%86%E7%BE%A4%E6%B7%B7%E4%B9%B1%E6%8E%92%E6%9F%A5%E5%92%8C%E5%A4%8D%E7%8E%B0/" itemprop="url">
        
        </a>
      </h1>
      <div class="post-meta">
      <span class="post-time">
<span class="post-meta-item-icon">
    <i class="fa fa-calendar-o"></i>
</span>
<span class="post-meta-item-text">时间：</span>
<time itemprop="dateCreated" datetime="2016-03-22T13:04:35+08:00" content="0001-01-01">
    0001-01-01
</time>
</span> 
      
      
       <span>
&nbsp; | &nbsp;
<span class="post-meta-item-icon">
    <i class="fa fa-eye"></i>
</span>
<span class="post-meta-item-text">阅读：</span>
<span class="leancloud-visitors-count">5411 字 ~26分钟</span>
</span>
      </div>
    </header>
    <div class="post-body" itemprop="articleBody">
    

    <blockquote>
<p>背景，公司的缓存管理云平台的实例克隆功能(机器宕机后将宕机的实例在其他服务器进行启动，然后与原集群进行主从关系维护)，在一次拷贝以后出现了集群混乱，初步定位为集群在下线实例的时候，没有成功forget掉下线的节点，集群中仍然有该实例的ip:port信息，但是状态为fail状态，当该ip和端口再度启动并加入其他集群时，自动被原集群召回，导致集群混乱。</p>
</blockquote>
<p>目前需要确认几个问题：</p>
<ol>
<li>集群是否会有脏数据（指的是不同集群冲突槽位的数据是否混淆）</li>
<li>集群混乱的触发原因是什么</li>
<li>集群混乱以后槽位、数据的覆盖的逻辑</li>
</ol>
<h2 id="一环境准备">一、环境准备</h2>
<p>准备4台CENTOS虚拟机服务器，ip设置如下。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221
10.4.7.222
10.4.7.223
10.4.7.224
</code></pre></div><p>集群规划如下，三个集群分别部署在221、222、223三台机器上，224作为克隆机器。集群的主从端口要有相应规则，如 8001为主，8011为从，这样一方面方便编写启动和集群匹配主从的脚本，另一方面，方便集群混乱以后查看集群的节点的情况。</p>
<p>A 3主3从</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:8001
10.4.7.222:8011

10.4.7.222:8002
10.4.7.223:8012

10.4.7.223:8003
10.4.7.221:8013
</code></pre></div><p>B 4主4从</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:9001
10.4.7.222:9011

10.4.7.222:9002
10.4.7.223:9012

10.4.7.223:9003
10.4.7.221:9013

10.4.7.221:9004
10.4.7.222:9014
</code></pre></div><p>C 5主5从</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:7001
10.4.7.222:7011

10.4.7.222:7002
10.4.7.223:7012

10.4.7.223:7003
10.4.7.221:7013

10.4.7.221:7004
10.4.7.222:7014

10.4.7.222:7005
10.4.7.223:7015
</code></pre></div><p>目录规划</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">日志文件目录
/app/cachecloud/logs
配置文件目录
/app/cachecloud/conf
数据文件目录
/app/cachecloud/data
</code></pre></div><p>配置文件模板，将所有规划的实例的配置文件都创建在<code>/app/cachecloud/conf</code>目录下，redis安装编译步骤省略。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">port 8001
cluster-enabled yes
cluster-node-timeout 15000
cluster-config-file &#34;nodes-8001.conf&#34;
bind 0.0.0.0
daemonize yes
logfile &#34;/app/cachecloud/logs/redis-a-8001.log&#34;
dir /app/cachecloud/data
dbfilename dump-8001.rdb
</code></pre></div><p>分别执行调整配置</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#8f5902;font-style:italic">#关闭linux大页设置</span>
<span style="color:#204a87">echo</span> never &gt; /sys/kernel/mm/transparent_hugepage/enabled
<span style="color:#8f5902;font-style:italic">#内核允许分配所有的物理内存，而不管当前的内存状态如何。</span>
<span style="color:#204a87">echo</span> <span style="color:#0000cf;font-weight:bold">1</span> &gt; /proc/sys/vm/overcommit_memory
sysctl vm.overcommit_memory<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">1</span>
<span style="color:#8f5902;font-style:italic">#关闭防火墙(很重要，否则集群通信会失败)</span>
systemctl stop firewalld
</code></pre></div><p>重新配置集群,删除配置（kill redis进程，删除缓存的集群nodes配置文件、日志文件、数据文件）</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">cd</span> /app/cachecloud/conf<span style="color:#000;font-weight:bold">;</span>ps -ef <span style="color:#000;font-weight:bold">|</span> grep redis-server <span style="color:#000;font-weight:bold">|</span> grep -v grep <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $2}&#39;</span> <span style="color:#000;font-weight:bold">|</span> xargs kill<span style="color:#000;font-weight:bold">;</span>rm -f dump.rdb nodes-*.conf<span style="color:#000;font-weight:bold">;</span>rm -f /app/cachecloud/logs/*.log<span style="color:#000;font-weight:bold">;</span>rm -f /app/cachecloud/data/*.rdb
</code></pre></div><p>221,222,223分别执行以下启动实例</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">cd</span> /app/cachecloud/conf<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">for</span> i in <span style="color:#4e9a06">`</span>ls -l <span style="color:#000;font-weight:bold">|</span> grep redis <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $9}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">do</span> <span style="color:#204a87">echo</span> <span style="color:#4e9a06">`</span>redis-server <span style="color:#000">$i</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span> <span style="color:#204a87;font-weight:bold">done</span><span style="color:#000;font-weight:bold">;</span>
</code></pre></div><p>在221服务器执行meet集群节点命令</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#8f5902;font-style:italic">#集群A</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">8001</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">8011</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">8002</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">8012</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">8003</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">8013</span>

<span style="color:#8f5902;font-style:italic">#集群B</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">9001</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">9011</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">9002</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">9012</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">9003</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">9013</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">9004</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">9014</span>

集群C
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">7001</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">7011</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">7002</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">7012</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">7003</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">7013</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.221 <span style="color:#0000cf;font-weight:bold">7004</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">7014</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.222 <span style="color:#0000cf;font-weight:bold">7005</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">7015</span>
</code></pre></div><p>给三个集群分配槽位，集群实例分配的槽位细碎一些</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>0..5555<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">8002</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>5556..11112<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">8003</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>11113..16383<span style="color:#ce5c00;font-weight:bold">}</span>

redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>0..4096<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9002</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>4097..8192<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">9003</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>8193..12288<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9004</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>12289..16383<span style="color:#ce5c00;font-weight:bold">}</span>

redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>0..3278<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7002</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>3279..6556<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7003</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>6557..9834<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7004</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>9835..13112<span style="color:#ce5c00;font-weight:bold">}</span>
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7005</span> cluster addslots <span style="color:#ce5c00;font-weight:bold">{</span>13113..16383<span style="color:#ce5c00;font-weight:bold">}</span>
</code></pre></div><p>221执行主从对应</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :8001 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">8011</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :8002 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">8012</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :8003 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8013</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :9001 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9011</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :9002 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">9012</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :9003 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9013</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :9004 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9014</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>

<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :7001 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7011</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :7002 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7012</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :7003 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7013</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :7004 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7014</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep :7005 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7015</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
</code></pre></div><p>集群准备好以后，查看集群的状态，每次执行操作以后都要记录一下，便于比对实例的变更状态。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes


<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189621790</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 5556-11112
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave b850d083307af116b1f61401cb7d01e2d162ad38 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189623797</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-5555
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 slave e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189624800</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189623295</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189622794</span> <span style="color:#0000cf;font-weight:bold">5</span> connected 11113-16383

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189622893</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189619884</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189620888</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 slave ca7e61ba84d005dc32570377a7e57cdc2b1ea395 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189617878</span> <span style="color:#0000cf;font-weight:bold">3</span> connected
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189623898</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189621891</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189622392</span> <span style="color:#0000cf;font-weight:bold">2</span> connected 8193-12288
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189621892</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected 0-3278
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189623900</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189624904</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 6557-9834
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 slave 94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189620887</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189620387</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189622393</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189622894</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189622394</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 13113-16383
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648189619886</span> <span style="color:#0000cf;font-weight:bold">2</span> connected
</code></pre></div><p>执行python脚本向3个集群中各插入100w条数据，每个集群的数据要有自己的规则，便于查看集群混乱后的数据分布状况。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">time</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">traceback</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">random</span>
<span style="color:#204a87;font-weight:bold">from</span> <span style="color:#000">time</span> <span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">ctime</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">sleep</span>
<span style="color:#204a87;font-weight:bold">from</span> <span style="color:#000">rediscluster</span> <span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">StrictRedisCluster</span>

<span style="color:#8f5902;font-style:italic"># 生成随机字符串</span>
<span style="color:#204a87;font-weight:bold">def</span> <span style="color:#000">generate_random_str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">16</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#000">random_str</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">&#39;</span>
    <span style="color:#000">base_str</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789</span><span style="color:#4e9a06">&#39;</span>
    <span style="color:#000">length</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87">len</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">base_str</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#0000cf;font-weight:bold">1</span>
    <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">i</span> <span style="color:#204a87;font-weight:bold">in</span> <span style="color:#204a87">range</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
        <span style="color:#000">random_str</span> <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">base_str</span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">random</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">randint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">length</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">]</span>
    <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">random_str</span>

<span style="color:#204a87;font-weight:bold">def</span> <span style="color:#000">generate_random_num</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">100</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">random</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">randint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">randomlength</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#8f5902;font-style:italic"># 集群A</span>
<span style="color:#000">startup_nodes</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">[</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">8001</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">8011</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">8002</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">8012</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">8003</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">8013</span><span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">]</span>

<span style="color:#000">redis_conn</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">StrictRedisCluster</span><span style="color:#000;font-weight:bold">(</span>
    <span style="color:#000">startup_nodes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">startup_nodes</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">decode_responses</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#3465a4">True</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">password</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">&#39;</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#000">p</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">redis_conn</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">pipeline</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">i</span> <span style="color:#204a87;font-weight:bold">in</span> <span style="color:#204a87">range</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">1000000</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#000">p</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">set</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">cluster:A:hello_</span><span style="color:#4e9a06">&#39;</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#204a87">str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#000;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">zfill</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">8</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">generate_random_str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">10</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">if</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">%</span> <span style="color:#0000cf;font-weight:bold">1000</span> <span style="color:#ce5c00;font-weight:bold">==</span> <span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">:</span>
        <span style="color:#000">p</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">execute</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">)</span>
        <span style="color:#204a87;font-weight:bold">print</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">========&gt;executed:{}</span><span style="color:#4e9a06">&#34;</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">format</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">)</span>
</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">time</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">traceback</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">random</span>
<span style="color:#204a87;font-weight:bold">from</span> <span style="color:#000">time</span> <span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">ctime</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">sleep</span>
<span style="color:#204a87;font-weight:bold">from</span> <span style="color:#000">rediscluster</span> <span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">StrictRedisCluster</span>

<span style="color:#8f5902;font-style:italic"># 生成随机字符串</span>
<span style="color:#204a87;font-weight:bold">def</span> <span style="color:#000">generate_random_str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">16</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#000">random_str</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">&#39;</span>
    <span style="color:#000">base_str</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789</span><span style="color:#4e9a06">&#39;</span>
    <span style="color:#000">length</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87">len</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">base_str</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#0000cf;font-weight:bold">1</span>
    <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">i</span> <span style="color:#204a87;font-weight:bold">in</span> <span style="color:#204a87">range</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
        <span style="color:#000">random_str</span> <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">base_str</span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">random</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">randint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">length</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">]</span>
    <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">random_str</span>

<span style="color:#204a87;font-weight:bold">def</span> <span style="color:#000">generate_random_num</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">100</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">random</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">randint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">randomlength</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#8f5902;font-style:italic"># 集群B</span>
<span style="color:#000">startup_nodes</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">[</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9001</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9011</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9002</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9012</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9003</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9013</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9004</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">9014</span><span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">]</span>

<span style="color:#000">redis_conn</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">StrictRedisCluster</span><span style="color:#000;font-weight:bold">(</span>
    <span style="color:#000">startup_nodes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">startup_nodes</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">decode_responses</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#3465a4">True</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">password</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">&#39;</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#000">p</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">redis_conn</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">pipeline</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">i</span> <span style="color:#204a87;font-weight:bold">in</span> <span style="color:#204a87">range</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">1000000</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#8f5902;font-style:italic"># 字符串</span>
    <span style="color:#000">p</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">set</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">cluster:B:hello_</span><span style="color:#4e9a06">&#39;</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#204a87">str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#000;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">zfill</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">8</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">generate_random_str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">10</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">if</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">%</span> <span style="color:#0000cf;font-weight:bold">1000</span> <span style="color:#ce5c00;font-weight:bold">==</span> <span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">:</span>
        <span style="color:#000">p</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">execute</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">)</span>
        <span style="color:#204a87;font-weight:bold">print</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">========&gt;executed:{}</span><span style="color:#4e9a06">&#34;</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">format</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">)</span>

</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-python" data-lang="python"><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">redis</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">time</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">traceback</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">random</span>
<span style="color:#204a87;font-weight:bold">from</span> <span style="color:#000">time</span> <span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">ctime</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">sleep</span>
<span style="color:#204a87;font-weight:bold">from</span> <span style="color:#000">rediscluster</span> <span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">StrictRedisCluster</span>

<span style="color:#8f5902;font-style:italic"># 生成随机字符串</span>
<span style="color:#204a87;font-weight:bold">def</span> <span style="color:#000">generate_random_str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">16</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#000">random_str</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">&#39;</span>
    <span style="color:#000">base_str</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">ABCDEFGHIGKLMNOPQRSTUVWXYZabcdefghigklmnopqrstuvwxyz0123456789</span><span style="color:#4e9a06">&#39;</span>
    <span style="color:#000">length</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87">len</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">base_str</span><span style="color:#000;font-weight:bold">)</span> <span style="color:#ce5c00;font-weight:bold">-</span> <span style="color:#0000cf;font-weight:bold">1</span>
    <span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">i</span> <span style="color:#204a87;font-weight:bold">in</span> <span style="color:#204a87">range</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
        <span style="color:#000">random_str</span> <span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">base_str</span><span style="color:#000;font-weight:bold">[</span><span style="color:#000">random</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">randint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">length</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">]</span>
    <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">random_str</span>

<span style="color:#204a87;font-weight:bold">def</span> <span style="color:#000">generate_random_num</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">randomlength</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">100</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#204a87;font-weight:bold">return</span> <span style="color:#000">random</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">randint</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">randomlength</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#8f5902;font-style:italic"># 集群C</span>
<span style="color:#000">startup_nodes</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000;font-weight:bold">[</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7001</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7011</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7002</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7012</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7003</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7013</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.221</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7004</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7014</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.222</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7005</span><span style="color:#000;font-weight:bold">}</span><span style="color:#000;font-weight:bold">,</span>
    <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">host</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">10.4.7.223</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">,</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">port</span><span style="color:#4e9a06">&#34;</span><span style="color:#000;font-weight:bold">:</span> <span style="color:#0000cf;font-weight:bold">7015</span><span style="color:#000;font-weight:bold">}</span>
<span style="color:#000;font-weight:bold">]</span>


<span style="color:#000">redis_conn</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">StrictRedisCluster</span><span style="color:#000;font-weight:bold">(</span>
    <span style="color:#000">startup_nodes</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">startup_nodes</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">decode_responses</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#3465a4">True</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">password</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">&#39;</span><span style="color:#000;font-weight:bold">)</span>

<span style="color:#000">p</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">redis_conn</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">pipeline</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">)</span>
<span style="color:#204a87;font-weight:bold">for</span> <span style="color:#000">i</span> <span style="color:#204a87;font-weight:bold">in</span> <span style="color:#204a87">range</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#0000cf;font-weight:bold">1000000</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">:</span>
    <span style="color:#8f5902;font-style:italic"># 字符串</span>
    <span style="color:#000">p</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">set</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#39;</span><span style="color:#4e9a06">cluster:C:hello_</span><span style="color:#4e9a06">&#39;</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#204a87">str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#000;font-weight:bold">)</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">zfill</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">8</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">generate_random_str</span><span style="color:#000;font-weight:bold">(</span><span style="color:#0000cf;font-weight:bold">10</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">)</span>
    <span style="color:#204a87;font-weight:bold">if</span> <span style="color:#000">i</span> <span style="color:#ce5c00;font-weight:bold">%</span> <span style="color:#0000cf;font-weight:bold">1000</span> <span style="color:#ce5c00;font-weight:bold">==</span> <span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">:</span>
        <span style="color:#000">p</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">execute</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000;font-weight:bold">)</span>
        <span style="color:#204a87;font-weight:bold">print</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06"></span><span style="color:#4e9a06">&#34;</span><span style="color:#4e9a06">========&gt;executed:{}</span><span style="color:#4e9a06">&#34;</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#000">format</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">i</span><span style="color:#000;font-weight:bold">)</span><span style="color:#000;font-weight:bold">)</span>
</code></pre></div><p>插入数据后记录一下集群各节点的数据数量和内存占用，用于比对集群混乱后的的数据分布情况。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">8002</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">8003</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9002</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">9003</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9004</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7002</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7003</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7004</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7005</span> dbsize

redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">8011</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">8012</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8013</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9011</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">9012</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9013</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9014</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7011</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7012</span> dbsize
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7013</span> dbsize
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7014</span> dbsize
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7015</span> dbsize

redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">8002</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">8003</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9002</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">9003</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9004</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7002</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7003</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7004</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7005</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human

redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">8011</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">8012</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8013</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9011</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">9012</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9013</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">9014</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7011</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7012</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7013</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.222 -p <span style="color:#0000cf;font-weight:bold">7014</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human
redis-cli -h 10.4.7.223 -p <span style="color:#0000cf;font-weight:bold">7015</span> info memory <span style="color:#000;font-weight:bold">|</span> grep used_memory_human



<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 8001 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">338674</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 8002 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">338920</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 8003 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">321407</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 9001 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249806</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 9002 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249755</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 9003 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249754</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 9004 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249686</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 7001 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199887</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7002 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199862</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 7003 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">200014</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 7004 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199857</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7005 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199381</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 8011 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">338674</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 8012 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">338920</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 8013 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">321407</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 9011 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249806</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 9012 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249755</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 9013 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249754</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 9014 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">249686</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7011 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199887</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 7012 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199862</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 7013 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">200014</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7014 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199857</span>
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 7015 dbsize</span>
<span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> <span style="color:#0000cf;font-weight:bold">199381</span>


<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 8001 info memory | grep used_memory_human</span>
used_memory_human:65.04M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 8002 info memory | grep used_memory_human</span>
used_memory_human:65.09M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 8003 info memory | grep used_memory_human</span>
used_memory_human:62.05M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 9001 info memory | grep used_memory_human</span>
used_memory_human:47.64M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 9002 info memory | grep used_memory_human</span>
used_memory_human:47.64M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 9003 info memory | grep used_memory_human</span>
used_memory_human:47.65M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 9004 info memory | grep used_memory_human</span>
used_memory_human:47.63M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 7001 info memory | grep used_memory_human</span>
used_memory_human:39.01M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7002 info memory | grep used_memory_human</span>
used_memory_human:39.01M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 7003 info memory | grep used_memory_human</span>
used_memory_human:39.03M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 7004 info memory | grep used_memory_human</span>
used_memory_human:39.01M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7005 info memory | grep used_memory_human</span>
used_memory_human:38.97M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 8011 info memory | grep used_memory_human</span>
used_memory_human:64.03M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 8012 info memory | grep used_memory_human</span>
used_memory_human:64.07M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 8013 info memory | grep used_memory_human</span>
used_memory_human:61.08M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 9011 info memory | grep used_memory_human</span>
used_memory_human:46.64M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 9012 info memory | grep used_memory_human</span>
used_memory_human:46.64M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 9013 info memory | grep used_memory_human</span>
used_memory_human:46.65M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 9014 info memory | grep used_memory_human</span>
used_memory_human:46.63M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7011 info memory | grep used_memory_human</span>
used_memory_human:38.02M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 7012 info memory | grep used_memory_human</span>
used_memory_human:38.01M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.221 -p 7013 info memory | grep used_memory_human</span>
used_memory_human:38.04M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.222 -p 7014 info memory | grep used_memory_human</span>
used_memory_human:38.02M
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -h 10.4.7.223 -p 7015 info memory | grep used_memory_human</span>
used_memory_human:37.93M

</code></pre></div><h2 id="二关机迁移实例到其他服务器启动">二、关机迁移实例到其他服务器启动</h2>
<p>将223服务器的配置文件拷贝到224服务器相同目录上。然后223服务器关机，模拟服务器宕机情景。</p>
<p>224执行启动223相同配置实例的脚本：</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">cd</span> /app/cachecloud/conf<span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">for</span> i in <span style="color:#4e9a06">`</span>ls -l <span style="color:#000;font-weight:bold">|</span> grep redis <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $9}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span><span style="color:#204a87;font-weight:bold">do</span> <span style="color:#204a87">echo</span> <span style="color:#4e9a06">`</span>redis-server <span style="color:#000">$i</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span> <span style="color:#204a87;font-weight:bold">done</span><span style="color:#000;font-weight:bold">;</span>
</code></pre></div><p>224执行 meet新启动的实例到原来的集群</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">8012</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">8003</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">9012</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">9003</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">7012</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">7003</span>
redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.224 <span style="color:#0000cf;font-weight:bold">7015</span>
</code></pre></div><p>224 执行 主从对应脚本</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :8013 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">8003</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :8002 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">8012</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :9013 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">9003</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :9002 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">9012</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :7013 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">7003</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :7002 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">7012</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
<span style="color:#000">masternodeid</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">`</span>redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v 223:<span style="color:#000;font-weight:bold">|</span> grep :7005 <span style="color:#000;font-weight:bold">|</span> awk <span style="color:#4e9a06">&#39;{print $1}&#39;</span><span style="color:#4e9a06">`</span><span style="color:#000;font-weight:bold">;</span>redis-cli -h 10.4.7.224 -p <span style="color:#0000cf;font-weight:bold">7015</span> cluster replicate <span style="color:#000">$masternodeid</span><span style="color:#000;font-weight:bold">;</span>
</code></pre></div><p>记录下集群的节点状态:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes


<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196595409</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 5556-11112
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave b850d083307af116b1f61401cb7d01e2d162ad38 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196597418</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-5555
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196596412</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 11113-16383
367718bbbc764cfa68d965fa680daa9eaa761917 10.4.7.224:8012 slave b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196593902</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
d2bf2df82f454d7a8ffc3be86a7b1d6f63f41df8 10.4.7.224:8003 slave 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196591390</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196453603</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed 10.4.7.223:8003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457116</span> <span style="color:#0000cf;font-weight:bold">1648196456616</span> <span style="color:#0000cf;font-weight:bold">5</span> connected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196597418</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196592393</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
bd4d895a634d586d645a3b2fe3f0d5217e9d1f32 10.4.7.224:9003 slave 577e5ea9c7f56c3767cfcfa23905742d97448b02 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196593903</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196597917</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196595408</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196596413</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 10.4.7.223:9003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">2</span> connected
d8ed793b07efaad87a03315808f9e92b462f2fff 10.4.7.224:9012 slave 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196594405</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
ba48e3d56b1405af07e34e6fbc34264fe4b893a6 10.4.7.224:7015 slave 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196594406</span> <span style="color:#0000cf;font-weight:bold">11</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196597418</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected 0-3278
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196596915</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
1fca4edaf4d453ac3daddbae0ed23f64370a5bf6 10.4.7.224:7012 slave 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196595409</span> <span style="color:#0000cf;font-weight:bold">12</span> connected
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196592393</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
7cf3322b4c2da99138b4daf121c336087ee2fd05 10.4.7.224:7003 slave 955014596d1929366f655ad6a020195432da917e <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196595209</span> <span style="color:#0000cf;font-weight:bold">13</span> connected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196449588</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196598420</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196593400</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 13113-16383
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196596414</span> <span style="color:#0000cf;font-weight:bold">2</span> connected
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span>#
</code></pre></div><p>等一会A、B、C集群主从节点数据同步完成
224执行关机，模拟服务器宕机状态。</p>
<p>记录下集群个节点状态：</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196853711</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 5556-11112
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave b850d083307af116b1f61401cb7d01e2d162ad38 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196851701</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-5555
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196852704</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 11113-16383
367718bbbc764cfa68d965fa680daa9eaa761917 10.4.7.224:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196696080</span> <span style="color:#0000cf;font-weight:bold">1648196690858</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
d2bf2df82f454d7a8ffc3be86a7b1d6f63f41df8 10.4.7.224:8003 slave,fail 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">1648196696081</span> <span style="color:#0000cf;font-weight:bold">1648196694878</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196453603</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed 10.4.7.223:8003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457116</span> <span style="color:#0000cf;font-weight:bold">1648196456616</span> <span style="color:#0000cf;font-weight:bold">5</span> connected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196853611</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196853106</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
bd4d895a634d586d645a3b2fe3f0d5217e9d1f32 10.4.7.224:9003 slave,fail 577e5ea9c7f56c3767cfcfa23905742d97448b02 <span style="color:#0000cf;font-weight:bold">1648196696058</span> <span style="color:#0000cf;font-weight:bold">1648196694353</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196850595</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196851599</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196852605</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 10.4.7.223:9003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">2</span> connected
d8ed793b07efaad87a03315808f9e92b462f2fff 10.4.7.224:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196696059</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
ba48e3d56b1405af07e34e6fbc34264fe4b893a6 10.4.7.224:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196696163</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">11</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196850597</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected 0-3278
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196855119</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
1fca4edaf4d453ac3daddbae0ed23f64370a5bf6 10.4.7.224:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196689348</span> <span style="color:#0000cf;font-weight:bold">12</span> connected
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196854614</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
7cf3322b4c2da99138b4daf121c336087ee2fd05 10.4.7.224:7003 slave,fail 955014596d1929366f655ad6a020195432da917e <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196691350</span> <span style="color:#0000cf;font-weight:bold">13</span> connected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196449588</span> <span style="color:#0000cf;font-weight:bold">5</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196854112</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196852606</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 13113-16383
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648196849590</span> <span style="color:#0000cf;font-weight:bold">2</span> connected
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span>#
</code></pre></div><h2 id="三开始错位启动集群实例">三、开始错位启动集群实例</h2>
<p>223开机，关闭大页、设置内存分配机制、关闭防火墙</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">echo</span> never &gt; /sys/kernel/mm/transparent_hugepage/enabled
<span style="color:#204a87">echo</span> <span style="color:#0000cf;font-weight:bold">1</span> &gt; /proc/sys/vm/overcommit_memory
sysctl vm.overcommit_memory<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#0000cf;font-weight:bold">1</span>
systemctl stop firewalld
</code></pre></div><h3 id="1第一次错位集群实例启动测试">1）第一次错位集群实例启动测试</h3>
<p>223启动错位集群端口进行测试（此时并未删除rdb文件）,错位端口的实例要挑选原来在223服务器启动的关机后在集群中仍是fail状态的实例，如下所示。要将这些实例启动并meet到其他的集群，以复现集群错乱的情况。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">#集群A
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed 10.4.7.223:8003 master,fail - 1648196457116 1648196456616 5 connected
#集群B
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 10.4.7.223:9003 master,fail - 1648196457015 1648196454609 2 connected
#集群C
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - 1648196457015 1648196454609 6 connected
</code></pre></div><p>启动8003实例，看日志等集群开始同步数据，就将其meet到其他集群</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-server redis-a-8003.conf
</code></pre></div><p>等了一段时间，看实例的启动日志<code>/app/cachecloud/logs/redis-a-8003.log</code>，未进行数据同步</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">223服务器8003实例启动日志
1415:M 25 Mar 16:30:56.808 * Increased maximum number of open files to 10032 (it was originally set to 1024).
1415:M 25 Mar 16:30:56.811 * No cluster configuration found, I&#39;m f91f4853ed6b725e5aff15377e887b25bb53bee3
1415:M 25 Mar 16:30:56.813 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1415:M 25 Mar 16:30:56.813 # Server started, Redis version 3.2.3
1415:M 25 Mar 16:30:56.814 * DB loaded from disk: 0.000 seconds
1415:M 25 Mar 16:30:56.814 * The server is now ready to accept connections on port 8003
1415:M 25 Mar 16:30:56.893 # IP address for this node updated to 10.4.7.223
</code></pre></div><p>等一段时间集群发现未进行数据同步，将端口meet到其他的集群中（原来是800x端口的A集群，由7001端口的C集群将节点meet进来）</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">8003</span>
</code></pre></div><p>原A集群节点实例正常meet到其他集群C集群中，未复现除集群错乱情况。
<!-- raw HTML omitted -->PS: 这里要注意，要由其他节点meet本机实例，而不要由本机实例meet其他集群实例，因为正常的流程是 启动实例 -&gt; meet节点 -&gt; 主从配对，本次试验要复现的是启动节点后原集群发现当前实例，然后进行主从数据同步，然后再由其他集群将本实例meet进来，两步操作不能太快，否则不能复现除那种情况。 <!-- raw HTML omitted --></p>
<p>记录下当前A、B、C节点的状态</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes


<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197599294</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 5556-11112
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave b850d083307af116b1f61401cb7d01e2d162ad38 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197593238</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-5555
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197600302</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 11113-16383
367718bbbc764cfa68d965fa680daa9eaa761917 10.4.7.224:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196696080</span> <span style="color:#0000cf;font-weight:bold">1648196690858</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
d2bf2df82f454d7a8ffc3be86a7b1d6f63f41df8 10.4.7.224:8003 slave,fail 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">1648196696081</span> <span style="color:#0000cf;font-weight:bold">1648196694878</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196453603</span> <span style="color:#0000cf;font-weight:bold">4</span> disconnected
<span style="color:#8f5902;font-style:italic">#原集群的该端口实例的fail信息变成了  :0 master,fail,noaddr</span>
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457116</span> <span style="color:#0000cf;font-weight:bold">1648196456616</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197599901</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197599399</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
bd4d895a634d586d645a3b2fe3f0d5217e9d1f32 10.4.7.224:9003 slave,fail 577e5ea9c7f56c3767cfcfa23905742d97448b02 <span style="color:#0000cf;font-weight:bold">1648196696058</span> <span style="color:#0000cf;font-weight:bold">1648196694353</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197600405</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197598390</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197596371</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 10.4.7.223:9003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">2</span> disconnected
d8ed793b07efaad87a03315808f9e92b462f2fff 10.4.7.224:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196696059</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
ba48e3d56b1405af07e34e6fbc34264fe4b893a6 10.4.7.224:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196696163</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">11</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197600409</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197599907</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
1fca4edaf4d453ac3daddbae0ed23f64370a5bf6 10.4.7.224:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196689348</span> <span style="color:#0000cf;font-weight:bold">12</span> connected
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">6</span> disconnected
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197596875</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
7cf3322b4c2da99138b4daf121c336087ee2fd05 10.4.7.224:7003 slave,fail 955014596d1929366f655ad6a020195432da917e <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196691350</span> <span style="color:#0000cf;font-weight:bold">13</span> connected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">7</span> disconnected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196449588</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197600910</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197599907</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197595867</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 13113-16383
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648197597887</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
</code></pre></div><h3 id="2第二次错位集群实例启动测试">2）第二次错位集群实例启动测试</h3>
<p>223服务器继续启动错位集群端口进行测试</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">#集群B
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 10.4.7.223:9003 master,fail - 1648196457015 1648196454609 2 connected
</code></pre></div><p>启动9003实例，看日志等集群开始同步数据，就将其meet到其他集群，但未进行数据同步</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-server redis-b-9003.conf
</code></pre></div><p>端口启动以后，等一段时间集群发现未进行数据同步，然后由其他的集群加入meet该实例。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">9003</span>
</code></pre></div><p>正常加入meet到其他集群，未复现集群错乱情况。</p>
<p>记录下当前A、B、C集群各实例状态。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">
redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes


<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198584773</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 5556-11112
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave b850d083307af116b1f61401cb7d01e2d162ad38 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198581751</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-5555
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198583764</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 11113-16383
367718bbbc764cfa68d965fa680daa9eaa761917 10.4.7.224:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196696080</span> <span style="color:#0000cf;font-weight:bold">1648196690858</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
d2bf2df82f454d7a8ffc3be86a7b1d6f63f41df8 10.4.7.224:8003 slave,fail 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">1648196696081</span> <span style="color:#0000cf;font-weight:bold">1648196694878</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196453603</span> <span style="color:#0000cf;font-weight:bold">4</span> disconnected
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457116</span> <span style="color:#0000cf;font-weight:bold">1648196456616</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198582961</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198580441</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
bd4d895a634d586d645a3b2fe3f0d5217e9d1f32 10.4.7.224:9003 slave,fail 577e5ea9c7f56c3767cfcfa23905742d97448b02 <span style="color:#0000cf;font-weight:bold">1648196696058</span> <span style="color:#0000cf;font-weight:bold">1648196694353</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198581951</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198584973</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198583968</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">2</span> disconnected
d8ed793b07efaad87a03315808f9e92b462f2fff 10.4.7.224:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196696059</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
ba48e3d56b1405af07e34e6fbc34264fe4b893a6 10.4.7.224:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196696163</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">11</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198586039</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198580979</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
1fca4edaf4d453ac3daddbae0ed23f64370a5bf6 10.4.7.224:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196689348</span> <span style="color:#0000cf;font-weight:bold">12</span> connected
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">6</span> disconnected
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198585532</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
7cf3322b4c2da99138b4daf121c336087ee2fd05 10.4.7.224:7003 slave,fail 955014596d1929366f655ad6a020195432da917e <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196691350</span> <span style="color:#0000cf;font-weight:bold">13</span> connected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">7</span> disconnected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196449588</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
41b5990df1d6b1f41409c3fbfc98e696a37a3cac 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198582499</span> <span style="color:#0000cf;font-weight:bold">15</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198584519</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198581992</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198583509</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 13113-16383
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198581484</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
</code></pre></div><h3 id="3第三次错位集群实例启动测试">3）第三次错位集群实例启动测试</h3>
<p>223继续启动错位集群端口进行测试</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">#集群C
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - 1648196457015 1648196454609 6 connected
</code></pre></div><p>启动7003实例，看日志等集群开始同步数据，就将其meet到其他集群</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">redis-server redis-c-7003.conf
</code></pre></div><p>未进行数据同步，记录下集群各实例状态。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198837001</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 5556-11112
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave b850d083307af116b1f61401cb7d01e2d162ad38 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198839017</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-5555
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198838007</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 11113-16383
367718bbbc764cfa68d965fa680daa9eaa761917 10.4.7.224:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196696080</span> <span style="color:#0000cf;font-weight:bold">1648196690858</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
d2bf2df82f454d7a8ffc3be86a7b1d6f63f41df8 10.4.7.224:8003 slave,fail 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">1648196696081</span> <span style="color:#0000cf;font-weight:bold">1648196694878</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196453603</span> <span style="color:#0000cf;font-weight:bold">4</span> disconnected
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457116</span> <span style="color:#0000cf;font-weight:bold">1648196456616</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198837202</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198838211</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
bd4d895a634d586d645a3b2fe3f0d5217e9d1f32 10.4.7.224:9003 slave,fail 577e5ea9c7f56c3767cfcfa23905742d97448b02 <span style="color:#0000cf;font-weight:bold">1648196696058</span> <span style="color:#0000cf;font-weight:bold">1648196694353</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198839215</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198836697</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198837706</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">2</span> disconnected
d8ed793b07efaad87a03315808f9e92b462f2fff 10.4.7.224:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196696059</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
ba48e3d56b1405af07e34e6fbc34264fe4b893a6 10.4.7.224:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196696163</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">11</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198837708</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198836701</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
1fca4edaf4d453ac3daddbae0ed23f64370a5bf6 10.4.7.224:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196689348</span> <span style="color:#0000cf;font-weight:bold">12</span> connected
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">6</span> disconnected
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198837203</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
7cf3322b4c2da99138b4daf121c336087ee2fd05 10.4.7.224:7003 slave,fail 955014596d1929366f655ad6a020195432da917e <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196691350</span> <span style="color:#0000cf;font-weight:bold">13</span> connected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">7</span> disconnected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196449588</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
41b5990df1d6b1f41409c3fbfc98e696a37a3cac 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198834178</span> <span style="color:#0000cf;font-weight:bold">15</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198838211</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198836198</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198834178</span> <span style="color:#0000cf;font-weight:bold">3</span> connected 13113-16383
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198839221</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
c905ac47b6a74a6be2ae6ef2acb102b86463a192 10.4.7.223:7003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648198835187</span> <span style="color:#0000cf;font-weight:bold">16</span> connected
</code></pre></div><p>端口启动以后，等一段时间集群发现未进行数据同步，执行命令将端口meet到其他的集群中</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -h 10.4.7.221 -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster meet 10.4.7.223 <span style="color:#0000cf;font-weight:bold">7003</span>
</code></pre></div><p>查看集群状态，出现了集群混乱，从数据查看，发现集群A和集群C的节点已经混乱。现象是两个集群的实例数已经完全一致了，原来分属两个集群的实例，现在分别同时在两个集群中出现。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes 
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes</span>
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 slave 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199003766</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199007813</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 myself,slave 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected
c905ac47b6a74a6be2ae6ef2acb102b86463a192 10.4.7.223:7003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199004272</span> <span style="color:#0000cf;font-weight:bold">16</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199001749</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199003261</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199007812</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199005282</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199006798</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
e656d5a698046fcc4ccd341f0b9bdaf172f2d5ed :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457116</span> <span style="color:#0000cf;font-weight:bold">1648196456616</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 slave 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199006798</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
25c3ef545c93e7f55b9a86d3841ae6216eb66582 10.4.7.223:7015 handshake - <span style="color:#0000cf;font-weight:bold">1648198996399</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> disconnected
cef209f7ad1684972b3519df39884daf7e3b33a3 10.4.7.224:7003 handshake - <span style="color:#0000cf;font-weight:bold">1648198997712</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
367718bbbc764cfa68d965fa680daa9eaa761917 10.4.7.224:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196696080</span> <span style="color:#0000cf;font-weight:bold">1648196690858</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
41b5990df1d6b1f41409c3fbfc98e696a37a3cac 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199001245</span> <span style="color:#0000cf;font-weight:bold">15</span> connected
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199002249</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 13113-16383
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199007302</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
0afd6dd77395042026c1e358af7dd535fd4a5f0d 10.4.7.223:8012 slave,fail b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196453603</span> <span style="color:#0000cf;font-weight:bold">4</span> disconnected
9177fbf6d76a8fbf7fc615b7d3346f99fa1cc621 10.4.7.224:7015 handshake - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199006291</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
9c7ad087511eef9e0ce3707dc15b53870f34ecb4 10.4.7.224:7012 handshake - <span style="color:#0000cf;font-weight:bold">1648198997712</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
d2bf2df82f454d7a8ffc3be86a7b1d6f63f41df8 10.4.7.224:8003 slave,fail 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">1648196696081</span> <span style="color:#0000cf;font-weight:bold">1648196694878</span> <span style="color:#0000cf;font-weight:bold">6</span> connected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes</span>
cc4191deafddf42db21ee3cdab4f906931237ca9 10.4.7.223:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
37dc860d2cc031c7d0a052bb34c07ad1625cbe8f 10.4.7.222:9011 slave 335a0cb8d9d82a764a19bf71da6379b73c703e95 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199004633</span> <span style="color:#0000cf;font-weight:bold">7</span> connected
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199005637</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
bd4d895a634d586d645a3b2fe3f0d5217e9d1f32 10.4.7.224:9003 slave,fail 577e5ea9c7f56c3767cfcfa23905742d97448b02 <span style="color:#0000cf;font-weight:bold">1648196696058</span> <span style="color:#0000cf;font-weight:bold">1648196694353</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199006639</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199007644</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
dcf4c5f00f922e67094ebd0bf0cfe61701c0c3fe 10.4.7.222:9014 slave 097271ce6ad0d7c5b4e5b80a645058bd2bb0099f <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199002616</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
ca7e61ba84d005dc32570377a7e57cdc2b1ea395 :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">2</span> disconnected
d8ed793b07efaad87a03315808f9e92b462f2fff 10.4.7.224:9012 slave,fail 5f201e00106a512ab3a3d73455ee1269b367b204 <span style="color:#0000cf;font-weight:bold">1648196696059</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes</span>
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
b03eb3e887c67a6305c7a205d5bfc4d6e222dd74 10.4.7.222:8002 slave 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199004779</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
387564ccc40c9d38a335f9af6276fa4545456c3c 10.4.7.222:7014 slave 1f984fd46a8e343d9c421fbab04f1f5696e059d4 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199005283</span> <span style="color:#0000cf;font-weight:bold">9</span> connected
1fca4edaf4d453ac3daddbae0ed23f64370a5bf6 10.4.7.224:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196689348</span> <span style="color:#0000cf;font-weight:bold">12</span> connected
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199002755</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199003765</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 13113-16383
6312347acd744c21a57eea929316681ca5c89f3d 10.4.7.224:8003 handshake - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
ee340787e8a39a59f9169386bef30d70d2f1fb62 10.4.7.222:8011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199007813</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
3df4258d28c93acb80444e56a330c5331681d413 10.4.7.222:7005 slave 3e42b6080162017b33ae87caac67daad9eb77046 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199003264</span> <span style="color:#0000cf;font-weight:bold">6</span> connected
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199007811</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
ba48e3d56b1405af07e34e6fbc34264fe4b893a6 10.4.7.224:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196696163</span> <span style="color:#0000cf;font-weight:bold">1648196695859</span> <span style="color:#0000cf;font-weight:bold">11</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199005788</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 :0 master,fail,noaddr - <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454609</span> <span style="color:#0000cf;font-weight:bold">6</span> disconnected
3db9f8bb3bbadd6ddaacf61d9d2b0fd6cd883e54 10.4.7.223:7012 slave,fail 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196449588</span> <span style="color:#0000cf;font-weight:bold">5</span> disconnected
033229faffaede7d873acdc6d7c20a580ee9aa66 10.4.7.223:7015 slave,fail 3df4258d28c93acb80444e56a330c5331681d413 <span style="color:#0000cf;font-weight:bold">1648196457015</span> <span style="color:#0000cf;font-weight:bold">1648196454106</span> <span style="color:#0000cf;font-weight:bold">7</span> disconnected
7cf3322b4c2da99138b4daf121c336087ee2fd05 10.4.7.224:7003 slave,fail 955014596d1929366f655ad6a020195432da917e <span style="color:#0000cf;font-weight:bold">1648196696056</span> <span style="color:#0000cf;font-weight:bold">1648196691350</span> <span style="color:#0000cf;font-weight:bold">13</span> connected
41b5990df1d6b1f41409c3fbfc98e696a37a3cac 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199008822</span> <span style="color:#0000cf;font-weight:bold">15</span> connected
b850d083307af116b1f61401cb7d01e2d162ad38 10.4.7.221:8001 slave 87a0bf02cbc2e7eebee500840a346dc7d4fe2603 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199006798</span> <span style="color:#0000cf;font-weight:bold">4</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199008819</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
33ce47dc369d22aebfae29e9e8c39d48ad53e1aa 10.4.7.224:8012 handshake - <span style="color:#0000cf;font-weight:bold">1648198997711</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
966e18cfe9f02771752bac772918ec872d00bfb9 10.4.7.222:7011 slave e4aa6c4158b31d8d5f1aa048571f725522d521d7 <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199008315</span> <span style="color:#0000cf;font-weight:bold">14</span> connected
c905ac47b6a74a6be2ae6ef2acb102b86463a192 10.4.7.223:7003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199001747</span> <span style="color:#0000cf;font-weight:bold">16</span> connected
<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span>#

</code></pre></div><p>记录下集群混乱下各个集群的有效节点。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">redis-cli -p <span style="color:#0000cf;font-weight:bold">8001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v fail <span style="color:#000;font-weight:bold">|</span> grep -v handshake <span style="color:#000;font-weight:bold">|</span> grep -v slave
redis-cli -p <span style="color:#0000cf;font-weight:bold">9001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v fail <span style="color:#000;font-weight:bold">|</span> grep -v handshake <span style="color:#000;font-weight:bold">|</span> grep -v slave
redis-cli -p <span style="color:#0000cf;font-weight:bold">7001</span> cluster nodes <span style="color:#000;font-weight:bold">|</span> grep -v fail <span style="color:#000;font-weight:bold">|</span> grep -v handshake <span style="color:#000;font-weight:bold">|</span> grep -v slave

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 8001 cluster nodes | grep -v fail | grep -v handshake | grep -v slave</span>
c905ac47b6a74a6be2ae6ef2acb102b86463a192 10.4.7.223:7003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199296535</span> <span style="color:#0000cf;font-weight:bold">16</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199300058</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199294516</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199298045</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
41b5990df1d6b1f41409c3fbfc98e696a37a3cac 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199299555</span> <span style="color:#0000cf;font-weight:bold">15</span> connected
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199293000</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 13113-16383
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199295021</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199299055</span> <span style="color:#0000cf;font-weight:bold">0</span> connected

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 9001 cluster nodes | grep -v fail | grep -v handshake | grep -v slave</span>
5f201e00106a512ab3a3d73455ee1269b367b204 10.4.7.222:9002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199296628</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 4097-8192
577e5ea9c7f56c3767cfcfa23905742d97448b02 10.4.7.221:9013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199296122</span> <span style="color:#0000cf;font-weight:bold">8</span> connected 8193-12288
097271ce6ad0d7c5b4e5b80a645058bd2bb0099f 10.4.7.221:9004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199300160</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 12289-16383
335a0cb8d9d82a764a19bf71da6379b73c703e95 10.4.7.221:9001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1</span> connected 0-4096

<span style="color:#ce5c00;font-weight:bold">[</span>root@redis-7-221 conf<span style="color:#ce5c00;font-weight:bold">]</span><span style="color:#8f5902;font-style:italic"># redis-cli -p 7001 cluster nodes | grep -v fail | grep -v handshake | grep -v slave</span>
e4aa6c4158b31d8d5f1aa048571f725522d521d7 10.4.7.221:7001 myself,master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">14</span> connected 0-3278
955014596d1929366f655ad6a020195432da917e 10.4.7.221:7013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199298551</span> <span style="color:#0000cf;font-weight:bold">10</span> connected 6557-9834
3e42b6080162017b33ae87caac67daad9eb77046 10.4.7.221:8013 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199297542</span> <span style="color:#0000cf;font-weight:bold">6</span> connected 13113-16383
f91f4853ed6b725e5aff15377e887b25bb53bee3 10.4.7.223:8003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199299557</span> <span style="color:#0000cf;font-weight:bold">0</span> connected
87a0bf02cbc2e7eebee500840a346dc7d4fe2603 10.4.7.222:7002 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199299056</span> <span style="color:#0000cf;font-weight:bold">4</span> connected 3279-6556
41b5990df1d6b1f41409c3fbfc98e696a37a3cac 10.4.7.223:9003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199298049</span> <span style="color:#0000cf;font-weight:bold">15</span> connected
1f984fd46a8e343d9c421fbab04f1f5696e059d4 10.4.7.221:7004 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199298551</span> <span style="color:#0000cf;font-weight:bold">9</span> connected 9835-13112
c905ac47b6a74a6be2ae6ef2acb102b86463a192 10.4.7.223:7003 master - <span style="color:#0000cf;font-weight:bold">0</span> <span style="color:#0000cf;font-weight:bold">1648199300568</span> <span style="color:#0000cf;font-weight:bold">16</span> connected

</code></pre></div><p>错乱前集群的槽位分布</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">A集群
10.4.7.221 8001 {0..5555}
10.4.7.222 8002 {5556..11112}
10.4.7.223 8003 {11113..16383}
B集群
10.4.7.221 9001 {0..4096}
10.4.7.222 9002 {4097..8192}
10.4.7.223 9003 {8193..12288}
10.4.7.221 9004 {12289..16383}
C集群
10.4.7.221 7001 {0..3278}
10.4.7.222 7002 {3279..6556}
10.4.7.223 7003 {6557..9834}
10.4.7.221 7004 {9835..13112}
10.4.7.222 7005 {13113..16383}
</code></pre></div><p>集群错乱后槽位分布</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:7001 0-3278
10.4.7.222:7002 3279-6556
10.4.7.221:7013 6557-9834
10.4.7.221:7004 9835-13112
10.4.7.221:8013 13113-16383
</code></pre></div><p>可以看出槽位的分布与原C集群的槽位分布是相同的。查看各个实例的数据，可以看到集群的数据分布。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:7001 0-3278
10.4.7.222:7002 3279-6556
10.4.7.221:7013 6557-9834
#以上三个节点都是集群C的数据
10.4.7.221:7004 9835-13112
#以上一个节点都是集群A的数据
</code></pre></div><p>以下集群实例和纪元槽位的信息是在集群混乱前记录的，和混乱后集群的主节点数量和槽位分配契合</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">集群    		纪元	 槽位
集群A
10.4.7.222:8002 3	 5556-11112
10.4.7.222:8011 1	 
10.4.7.221:8001 1	 0-5555
10.4.7.221:8013 6	 11113-16383
集群C
10.4.7.222:7002 4	 3279-6556
10.4.7.221:7001 14	 0-3278
10.4.7.222:7014 9	
10.4.7.221:7013 10	 6557-9834
10.4.7.223:9003 15	
10.4.7.221:7004 9	 9835-13112
10.4.7.223:8003 0	
10.4.7.222:7005 3	 13113-16383
10.4.7.222:7011 14	
10.4.7.223:7003 16	
</code></pre></div><p>对比错乱前后的数据量和内存占用，可以看出，错乱前后槽位未变的情况下，实例的数据前后一致，内存差距不大。</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:7001 0-3278
10.4.7.222:7002 3279-6556
10.4.7.221:7013 6557-9834
10.4.7.221:7004 9835-13112
</code></pre></div><p>而槽位变化的实例，数据和内存变化则很大</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">10.4.7.221:8013 11113-16383 13113-16383
</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">数据量对比
                集群错乱后                       错乱前
10.4.7.221:8001 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199862		<span style="color:#0000cf;font-weight:bold">338674</span>
10.4.7.222:8002 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199862		<span style="color:#0000cf;font-weight:bold">338920</span>
10.4.7.223:8003 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 0			<span style="color:#0000cf;font-weight:bold">321407</span>
10.4.7.223:7003 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 0			<span style="color:#0000cf;font-weight:bold">200014</span>
*10.4.7.221:7004 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199857		<span style="color:#0000cf;font-weight:bold">199857</span>
10.4.7.222:7005 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199462		<span style="color:#0000cf;font-weight:bold">199381</span>
10.4.7.222:8011 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199887		<span style="color:#0000cf;font-weight:bold">338674</span>
10.4.7.223:8012 dbsize Connection refused	<span style="color:#0000cf;font-weight:bold">338920</span>
*10.4.7.221:8013 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199462		<span style="color:#0000cf;font-weight:bold">321407</span>
10.4.7.222:7011 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199887		<span style="color:#0000cf;font-weight:bold">199887</span>
10.4.7.223:7012 dbsize Connection refused	<span style="color:#0000cf;font-weight:bold">199862</span>
*10.4.7.221:7013 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 200014		<span style="color:#0000cf;font-weight:bold">200014</span>
10.4.7.222:7014 dbsize <span style="color:#ce5c00;font-weight:bold">(</span>integer<span style="color:#ce5c00;font-weight:bold">)</span> 199857		<span style="color:#0000cf;font-weight:bold">199857</span>
10.4.7.223:7015 dbsize Connection refused	<span style="color:#0000cf;font-weight:bold">199381</span>

查看各个实例的数据，均为各实例原所属集群的数据，并未出现同槽位数据合并、混淆的情况，冲突的槽位的数据以后覆盖槽位所属集群的为准。

内存对比
                错乱前  错乱后
10.4.7.221:8001 65.04M 39.11M
10.4.7.222:8002 65.09M 38.11M
10.4.7.223:8003 62.05M 1.42M
*10.4.7.221:7001 39.01M 39.13M
*10.4.7.222:7002 39.01M 39.13M
10.4.7.223:7003 39.03M 1.43M
*10.4.7.221:7004 39.01M 39.10M
10.4.7.222:7005 38.97M 38.03M
10.4.7.222:8011 64.03M 38.10M
10.4.7.223:8012 64.07M Connection refused
*10.4.7.221:8013 61.08M 41.05M
10.4.7.222:7011 38.02M 38.11M
10.4.7.223:7012 38.01M Connection refused
*10.4.7.221:7013 38.04M 39.11M
10.4.7.222:7014 38.02M 38.12M
10.4.7.223:7015 37.93M Connection refused
</code></pre></div><p>根据以上的试验结果，我们可以得出一个集群混乱的过程的一个脉络。</p>
<ol>
<li>集群C的一个实例在宕机后，在A集群中仍旧保留这fail状态
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">94985c7576c2a0ab05e3cb3bd3b63c75b137ddf3 10.4.7.223:7003 master,fail - 1648196457015 1648196454609 6 disconnected
</code></pre></div></li>
<li>在使用该实例的ip端口启动后，该实例被集群A召回。</li>
<li>从A集群Meet该实例节点，将该节点加入A集群</li>
<li>该节点是集群C的一个slave节点，同时又是集群A的一个新加入的master节点，此时，该节点与集群A集群C同时通信。认为是同一个集群。</li>
<li>集群内的所有节点，进行通讯，选除epoch纪元值最大的实例节点存储的集群信息向各个实例进行同步，所以集群A的3主3从和集群C的5主5从混合以后的主实例的数量是5主。就是选取了<code>10.4.7.223:7003实例，纪元epoch值为 16</code>这个最大的纪元的集群元信息。</li>
<li>拥有槽位的master实例，会向集群中的所有实例广播自己的带有纪元值的槽位信息，其他实例接收到后会更新自己记录的槽位关系信息，一个实例同时接受到多个拥有相同槽位的广播信息以后，会比较两个广播信息的epoch纪元值，将纪元值比较大的覆盖到自己的槽位关系信息中。从一下对比中，可以看到，最终的槽位信息的取值。
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-fallback" data-lang="fallback">集群    		纪元	 槽位
集群A
10.4.7.222:8002 3	 5556-11112
10.4.7.222:8011 1	 
10.4.7.221:8001 1	 0-5555
10.4.7.221:8013 6	 11113-16383
集群C
10.4.7.222:7002 4	 3279-6556
10.4.7.221:7001 14	 0-3278
10.4.7.222:7014 9	
10.4.7.221:7013 10	 6557-9834
10.4.7.223:9003 15	
10.4.7.221:7004 9	 9835-13112
10.4.7.223:8003 0	
10.4.7.222:7005 3	 13113-16383
10.4.7.222:7011 14	
10.4.7.223:7003 16	

集群C 10.4.7.221:7001 14	 0-3278
集群A 10.4.7.221:8001 1	 0-5555   =&gt; 0-3278的最大纪元实例为 集群C 10.4.7.221:7001

集群C 10.4.7.222:7002 4	 3279-6556
集群A 10.4.7.221:8001 1	 0-5555
集群A 10.4.7.222:8002 3	 5556-11112 =&gt; 3279-6556的最大纪元实例 为集群C 10.4.7.222:7002

集群C 10.4.7.221:7013 10	 6557-9834
集群A 10.4.7.222:8002 3	 5556-11112 =&gt; 6557-9834的最大纪元实例为 集群C 10.4.7.221:7013

集群C 10.4.7.221:7004 9	 9835-13112
集群A 10.4.7.221:8013 6	 11113-16383
集群A 10.4.7.222:8002 3	 5556-11112 =&gt; 9835-13112的最大纪元实例为 集群C 10.4.7.221:7004

集群C 10.4.7.222:7005 3	 13113-16383
集群A 10.4.7.221:8013 6	 11113-16383 =&gt; 13112-16383的最大纪元实例为 集群A 10.4.7.221:8013

最终的结果与集群胡乱后的槽位分布契合
10.4.7.221:7001 0-3278
10.4.7.222:7002 3279-6556
10.4.7.221:7013 6557-9834
10.4.7.221:7004 9835-13112
10.4.7.221:8013 13113-16383

从数据上看也是 0-13112槽位的数据都是原集群C的数据，而13113-16383的数据都是原集群A的数据。

</code></pre></div></li>
<li>从数据上来看，相同的槽位会被高纪元的实例的槽位进行覆盖，所以应该不回出现脏数据的情况。</li>
</ol>
<p>集群混乱的情况也并非每次都能复现，最开始我认为是只有关机后迁移的情况才能复现，后来关机后迁移也并不能够稳定的复现。目前我的猜测是，高纪元值的实例关闭后启动才会被原集群进行召回，因为每次测试的不确定因素就是这个纪元。</p>
<p>以上的结果，也只是这次执行的复现结果，在之前的几次操作流程中，还出现了丢槽位，槽位截断等现象，和集群和实例的纪元信息和槽位决策关联起来，就很好理解了。</p>
<p>复现过程要注意的几个点：</p>
<ol>
<li>机器开机后要注意关闭防火墙</li>
<li>启动实例以后不能太快操作meet和replicate，否则可能还来不及原集群发现该实例，新集群就已经操作成功了（也有可能是启动的实例在原集群的实例的纪元值太小所以不进行实例召回？暂不能确定）</li>
<li>关机或许并不能触发混乱的必要条件</li>
</ol>
<p>问题出现的原因分析：</p>
<ol>
<li>
<p>我们在做整机克隆时，在第一版的时候是没有做整个集群forget宕机实例的，第二版是做了的。但是第二版对整个集群执行了对宕机实例的forget，仍然有集群保留着宕机实例的fail信息，在<code>cluster forget</code>命令的文档中可以看到，<code>cluster forget</code> 这个命令必须在60秒内在所有的实例中执行，否则可能删除不掉集群信息中的宕机实例信息。而在宕机情况下，调用api连接宕机实例执行命令会超时返回无法执行，导致所有实例执行的时间超过60秒，然后集群信息中无法消除掉集群中的宕机实例信息。</p>
<blockquote>
<p><strong>命令执行详细</strong>
假设我们有四个节点:A,B,C,D。为了得到一个三节点群集A,B,C，我们可以做如下操作：</p>
<ol>
<li>将D上的哈希槽重分配到节点A,B,C。</li>
<li>节点D现在已经空了，但是节点A,B,C的节点信息表中仍然有D的信息</li>
<li>我们连接节点A，发送命令CLUSTER FORGET D。</li>
<li>节点B发送心跳包给节点A，包含节点D的信息。</li>
<li>节点A无节点D信息，无法识别节点D(参见步骤3)，因此开始与节点D握手。</li>
<li>节点D最终再次添加进节点A的节点信息表中</li>
</ol>
<p>上述的移除方法很不稳定，因此我们需要尽快发送命令CLUSTER FORGET 给所有节点，以期没有gossip sections在同时处理。 因为这个原因，命令CLUSTER FORGET为每个节点实现了包含超时时间的禁止列表
因此我们命令实际的执行情况如下：</p>
<ol>
<li>从收到命令节点的节点信息列表中删除待删除节点的节点信息。</li>
<li>已删除的节点的节点ID被加入禁止列表，保留1分钟</li>
<li>收到命令的节点，在处理从其他节点发送过来的gossip sections 会跳过所有在禁止列表中的节点。</li>
</ol>
<p>这样，我们就有60秒的时间窗口来通知群集中的所有节点，我们想要删除某个节点。</p>
</blockquote>
</li>
<li>
<p>该问题出现的场景是A服务器宕机，原A服务器的实例迁移到B服务服务器，然后A服务器维修好以后，回归资源池作为备用机，在C服务器宕机以后，将C服务器的实例迁移到A服务器时，正好C服务器上A1集群的中包含原来A服务器上的迁移走但是没forget掉的ip:port信息的实例。因为克隆功能已经上线很长时间了，以前并没有出现这种情况，以前克隆都是往新服务器上面克隆，而这次克隆是往以前宕机回收的机器上面克隆。所以发生了这次的情况。</p>
</li>
</ol>
<p>解决方案：</p>
<ol>
<li>定时检查集群信息，定时发现和清除fail状态的信息。</li>
<li>调整集群端口生成规则的最小值，大与现所有集群的实例的最大端口，避免新机器创建的新实例的端口与已有端口冲突。</li>
<li>宕机修复的机器修改ip。</li>
<li>执行<code>cluster forget</code>时不要直接使用for循环按序执行，而应该开多线程在60秒内执行完集群所有实例的<code>cluster forget</code>操作。</li>
</ol>
<h2 id="参考资料">参考资料：</h2>
<ol>
<li><a href="https://zhuanlan.zhihu.com/p/44658603">Redis 集群中的纪元(epoch)
</a></li>
<li><a href="http://redis.cn/commands/cluster-forget.html">CLUSTER FORGET node-id</a></li>
</ol>

    </div>
    <footer class="post-footer">
     

     <div class="post-nav">
    <div class="post-nav-next post-nav-item">
    
        <a href="http://www.shutdown.cn/post/%E5%9F%BA%E4%BA%8Eetcd%E5%AE%9E%E7%8E%B0%E5%A4%A7%E8%A7%84%E6%A8%A1%E6%9C%8D%E5%8A%A1%E6%B2%BB%E7%90%86%E5%BA%94%E7%94%A8%E5%AE%9E%E6%88%98/" rel="next" title="">
        <i class="fa fa-chevron-left"></i> 
        </a>
    
    </div>

    <div class="post-nav-prev post-nav-item">
    
        <a href="http://www.shutdown.cn/post/%E6%97%B6%E9%97%B4%E5%A4%8D%E6%9D%82%E5%BA%A6/" rel="prev" title="">
         <i class="fa fa-chevron-right"></i>
        </a>
    
    </div>
</div>
      
     
     
     






    </footer>
  </article>
</section>

          </div>
        </div>
        <div class="sidebar-toggle">
  <div class="sidebar-toggle-line-wrap">
    <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
    <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
  </div>
</div>
<aside id="sidebar" class="sidebar">
  <div class="sidebar-inner">

    <section class="site-overview sidebar-panel  sidebar-panel-active ">
      <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image"
        src="http://www.shutdown.cn/img/author.jpg"
        alt="不与天斗Domino" />
    <p class="site-author-name" itemprop="name">不与天斗Domino</p>
    <p class="site-description motion-element" itemprop="description"> 
        Programmer &amp; Architect</p>
</div>
      <nav class="site-state motion-element">
    <div class="site-state-item site-state-posts">
      <a href="http://www.shutdown.cn/post/">
        <span class="site-state-item-count">173</span>
        <span class="site-state-item-name">日志</span>
      </a>
    </div>
    <div class="site-state-item site-state-categories">    
        <a href="http://www.shutdown.cn/categories/">      
         
        <span class="site-state-item-count">5</span>
        
        <span class="site-state-item-name">分类</span>
        
        </a>
    </div>

    <div class="site-state-item site-state-tags">
        <a href="http://www.shutdown.cn/tags/">
         
        <span class="site-state-item-count">13</span>
        
        <span class="site-state-item-name">标签</span>
        </a>
    </div>
</nav>
      
      

      

      <div class="links-of-blogroll motion-element inline">
<script type="text/javascript" src="//rf.revolvermaps.com/0/0/8.js?i=&amp;m=0&amp;s=220&amp;c=ff0000&amp;cr1=ffffff&amp;f=arial&amp;l=33&amp;bv=35" async="async"></script>
</div>

    </section>
    
  </div>
</aside>

      </div>
    </main>
   
    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  <span itemprop="copyrightYear">  &copy; 
  2009 - 2022</span>
  <span class="with-love"><i class="fa fa-heart"></i></span>
  <span class="author" itemprop="copyrightHolder">天地维杰网</span>
  <span class="icp" itemprop="copyrightHolder"><a href="https://beian.miit.gov.cn/" target="_blank">京ICP备13019191号-1</a></span>
</div>
<div class="powered-by">
  Powered by - <a class="theme-link" href="http://gohugo.io" target="_blank" title="hugo" >Hugo v0.63.2</a>
</div>
<div class="theme-info">
  Theme by - <a class="theme-link" href="https://github.com/xtfly/hugo-theme-next" target="_blank"> NexT
  </a>
</div>


      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
      <span id="scrollpercent"><span>0</span>%</span>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery/index.js?v=2.1.3"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/fastclick/lib/fastclick.min.js?v=1.0.6"></script> 
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.min.js?v=1.2.1"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/vendor/velocity/velocity.ui.min.js?v=1.2.1"></script>
<script src="http://www.shutdown.cn/js/vendor/ua-parser-js/dist/ua-parser.min.js?v=0.7.9"></script>

<script src="http://www.shutdown.cn/js/vendor/fancybox/jquery.fancybox.pack.js?v=2.1.5"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/utils.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/motion.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/affix.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/schemes/pisces.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/scrollspy.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/post-details.js"></script>
<script type="text/javascript" src="http://www.shutdown.cn/js/toc.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/bootstrap.js"></script>

<script type="text/javascript" src="http://www.shutdown.cn/js/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX", "output/HTML-CSS"],
    tex2jax: {
      inlineMath: [ ['$','$'] ],
      displayMath: [ ['$$','$$'] ],
      processEscapes: true
    },
    "HTML-CSS": { fonts: ["TeX"] }
  });
</script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML' async></script>
</body>
</html>